package com.lxch.gdwxp.wxpay.wxpayconfig;

import com.github.wxpay.sdk.WXPay;

import com.lxch.gdwxp.wxpay.porperties.WXPayProperties;
import com.lxch.gdwxp.wxpay.service.WXPayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 微信支付自动配置类
 */
@Configuration
public class WXPAutoConfig {

    @Autowired
    private WXPayProperties wxPayProperties;

    @Bean
    public WXPayConfigImpl wxPayConfig() throws Exception {
        WXPayConfigImpl instance = new WXPayConfigImpl();
        instance.setWxPayProperties(wxPayProperties);
        System.out.println(instance + "======自动配置的WXPayConfigImpl类==============");
        return instance;
    }

    @Bean
    public WXPay wxPay() throws Exception {
        return new WXPay(wxPayConfig());
    }

    @Bean
    public WXPayService myWXPayUtil() {
        WXPayService myWXPayUtil = new WXPayService();
        myWXPayUtil.setWxPayProperties(wxPayProperties);
        return myWXPayUtil;
    }
}
